<?php
class brand_class extends CI_Controller {
	function index() {
		$this -> pub -> logp('浏览品牌分类', '1-2');
		$da = $this -> pub -> get_setting('品牌分类', 'Brands');
		$this -> load -> view('adminx/brand_class', $da);
	}

	function add() {
		$this -> pub -> logp('创建品牌分类', '1-2');
		$da['name'] = $this -> input -> post('name');
		$da['state'] = $this -> input -> post('state');
		$da['sort'] = $this -> input -> post('sort');
		$this -> db -> insert('sp_brand_class', $da);
		echo json_encode(array('type' => 1));
	}

	function up() {
		$this -> pub -> logp('品牌分类修改 - ' . $this -> input -> post('idx'), '1-2');
		$da['name'] = $this -> input -> post('name');
		$da['state'] = $this -> input -> post('state');
		$da['sort'] = $this -> input -> post('sort');
		$this -> db -> update('sp_brand_class', $da, array('id' => $this -> input -> post('idx')));
		echo json_encode(array('type' => 1));
	}

	function get_one() {
		$this -> pub -> logp('获取品牌分类信息 - ' . $this -> input -> post('idx'), '1-2');
		$q = $this -> db -> get_where('sp_brand_class', array('id' => $this -> input -> post('idx')));
		if ($q -> num_rows() > 0) {
			$da = $q -> row_array(0);
			$da['typex'] = 1;
			echo json_encode($da);
		} else {
			echo json_encode(array('typex' => 2));
		}
	}

	function get() {
		$this -> pub -> logp('获取品牌分类信息', '1-2');
		if ($this -> input -> post('key')) {
			$this -> db -> like('name', $this -> input -> post('key'));
		}
		$q = $this -> db -> get_where('sp_brand_class');
		$state[1] = '启用';
		$state[2] = '关闭';
		$da['content'] = '';

		foreach ($q->result_array() as $v) {
			$da['content'] .= '<tr>';
			$da['content'] .= '<td>' . $v['id'] . '</td>';
			$da['content'] .= '<td>' . $v['name'] . '</td>';
			$da['content'] .= '<td>' . $v['sort'] . '</td>';
			$da['content'] .= '<td>' . $state[$v['state']] . '</td>';
			$da['content'] .= '<td><button onclick="show_up(\'' . $v['id'] . '\')" type="button"  class="btn default"><i class="fa fa-edit"></i>修改</button></td>';
			$da['content'] .= '</tr>';
		}
		$da['type'] = 1;
		echo json_encode($da);
	}

}
?>